using System;
using System.Collections.Generic;
using System.Text;

namespace Deepcode.Flux.Core.UI.CMS
{
	public class CMSActionPane : Deepcode.Flux.Core.UI.AdministrationModulePage
	{
		#region Permission Code Override
		public override string RequiredPermissionCode { get { return "FluxCMSAccess"; } }
		#endregion
		#region ViewState and Properties
		/// <summary>
		/// Store the ID of the parent passed in to the action
		/// </summary>
		protected int ParentID
		{
			get
			{
				object o = ViewState["PID"];
				if (o == null) return -1;
				return (int)o;
			}
			set
			{
				ViewState["PID"] = value;
			}
		}
		/// <summary>
		/// Store the ID of the content passed to the actions
		/// </summary>
		protected int ContentID
		{
			get
			{
				object o = ViewState["CID"];
				if (o == null) return -1;
				return (int)o;
			}
			set
			{
				ViewState["CID"] = value;
			}
		}
		#endregion
		#region Page Load Event
		/// <summary>
		/// Page Load event
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		protected override void OnLoad(EventArgs e)
		{
			if (!Page.IsPostBack)
			{
				// Load path data
				ContentID = GetAttribute("ContentID", -1);
				ParentID = GetAttribute("ParentID", -1);
			}

			base.OnLoad(e);
		}
		#endregion
		#region Utility Methods
		/// <summary>
		/// Return back to the content tree without reloading
		/// </summary>
		protected virtual void GoBack()
		{
			GoBack( false );
		}
		/// <summary>
		/// Return back to the content tree, optionally reloading
		/// </summary>
		/// <param name="reload"></param>
		protected virtual void GoBack(bool reload)
		{
			// Revert back to content listing, reselect last selected if possible
			int iid = ContentID;
			if (iid == -1) iid = ParentID;
			string URL = String.Format(
				"~/admin/private/cms/main/content.aspx?selectID={0}{1}",
				iid.ToString(), 
				reload ? "&reload=true" : "" );

			Response.Redirect(URL, true );
		}
		#endregion
	}
}
